﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Foundation;
using System.Security.Cryptography;
using Google.Documents;


namespace BusinessEntity
{
    public static class GDocs
    {
        public static FileInfo[] GetLocalDocsList()
        {
            DirectoryInfo lDI = new DirectoryInfo(Constant.GDocsLocalRoot);
            return lDI.GetFiles();
        }

        public static void LoadOptions(out string lsUsername)
        {
            lsUsername = "";

            try
            {
                string lsEncUsername = "";
                string lsEncPassword = "";

                Utils.ReadRegistry(out lsEncUsername, out lsEncPassword);

                Encryptor lEncryptor = new Encryptor();

                if (lsEncUsername.Length > 0 && lsEncPassword.Length > 0)
                {
                    lsUsername = lEncryptor.Decrypto(lsEncUsername);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static bool SaveOptions(string lsUsername, string lsPassword)
        {
            bool lbRet = false;

            try
            {
                GDocsValidator.ValidateOnSaveOptions(lsUsername, lsPassword);

                Encryptor lEncryptor = new Encryptor();
                string lsEncUsername = lEncryptor.Encrypto(lsUsername);
                string lsEncPassword = lEncryptor.Encrypto(lsPassword);

                Utils.WriteRegistry(lsEncUsername, lsEncPassword);

                lbRet = true;
            }
            catch (Exception ex)
            {
                lbRet = false;
                throw ex;
            }

            return lbRet;
        }

        public static bool ClearOptions()
        {
            return Utils.ClearOptions();
        }


    }
}
